package cn.stylefeng.guns.modular.goodsEvaluate.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.goodsEvaluate.entity.TaoGoodsEvaluate;
import cn.stylefeng.guns.modular.goodsEvaluate.mapper.TaoGoodsEvaluateMapper;
import cn.stylefeng.guns.modular.goodsEvaluate.model.params.TaoGoodsEvaluateParam;
import cn.stylefeng.guns.modular.goodsEvaluate.model.result.TaoGoodsEvaluateResult;
import cn.stylefeng.guns.modular.goodsEvaluate.service.TaoGoodsEvaluateService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 商品评价 服务实现类
 * </p>
 *
 * @author lcw
 * @since 2019-11-01
 */
@Service
public class TaoGoodsEvaluateServiceImpl extends ServiceImpl<TaoGoodsEvaluateMapper, TaoGoodsEvaluate> implements TaoGoodsEvaluateService {

    @Override
    public void add(TaoGoodsEvaluateParam param){
        TaoGoodsEvaluate entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(TaoGoodsEvaluateParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(TaoGoodsEvaluateParam param){
        TaoGoodsEvaluate oldEntity = getOldEntity(param);
        TaoGoodsEvaluate newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public TaoGoodsEvaluateResult findBySpec(TaoGoodsEvaluateParam param){
        return null;
    }

    @Override
    public List<TaoGoodsEvaluateResult> findListBySpec(TaoGoodsEvaluateParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(TaoGoodsEvaluateParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(TaoGoodsEvaluateParam param){
        return null;
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private TaoGoodsEvaluate getOldEntity(TaoGoodsEvaluateParam param) {
        return this.getById(getKey(param));
    }

    private TaoGoodsEvaluate getEntity(TaoGoodsEvaluateParam param) {
        TaoGoodsEvaluate entity = new TaoGoodsEvaluate();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
